package com.rdzn.mall.center.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.rdzn.mall.center.entity.PmsComment;
import com.rdzn.mall.center.entity.PmsCommentReplay;
import com.rdzn.mall.center.mapper.PmsCommentReplayMapper;
import com.rdzn.mall.center.service.IPmsCommentReplayService;
import com.rdzn.mall.center.service.IPmsCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description: pms_comment_replay
 * @Author: jeecg-boot
 * @Date:   2020-08-27
 * @Version: V1.0
 */
@DS("mall")
@Service
public class PmsCommentReplayServiceImpl extends ServiceImpl<PmsCommentReplayMapper, PmsCommentReplay> implements IPmsCommentReplayService {

    @Autowired
    private IPmsCommentService commentService;

    @Override
    public List<PmsCommentReplay> listByProductId(Integer productId) {
        List<PmsComment> commentList = commentService.list(new LambdaQueryWrapper<PmsComment>().eq(PmsComment::getProductId, productId));
        if (CollectionUtils.isNotEmpty(commentList)){
            List<Integer> ids = commentList.stream().map(PmsComment::getId).collect(Collectors.toList());
            return list(new LambdaQueryWrapper<PmsCommentReplay>().in(PmsCommentReplay::getCommentId, ids));
        }
        return null;
    }
}
